package me.zingon.service.impl;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import freemarker.template.TemplateException;
import me.zingon.backup.util.Maps;
import me.zingon.backup.util.MyUtil;
import me.zingon.service.CreateService;

public class DtoServiceImpl {

    CreateService cs = CreateServiceImpl.getInstance();

    public int createModels() throws IOException, TemplateException {
        String path = MyUtil.mkDir("dto");

        List<String> tables = Maps.getTables();
        for (String table : tables) {
            Map<String, Object> root = new HashMap<String, Object>();
            root.put("model", MyUtil.a_b2AB(table));
            root.put("fields", Maps.getFields(table));
            cs.write2File(root, "Dto.ftl", new File(path + File.separator + MyUtil.a_b2AB(table) + "Dto.java"));
        }
        return 0;
    }
	
}
